package com.adcc.eoss.cawebservice.service.impl;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.adcc.eoss.cawebservice.domain.Pilot;
import com.adcc.eoss.cawebservice.domain.PilotRepository;
import com.adcc.eoss.cawebservice.service.PilotService;
import com.fasterxml.jackson.databind.ObjectMapper;

@Service
public class PilotServiceImpl implements PilotService {

	protected final Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private PilotRepository repository;
	
	@Override
	public String getPilot(String id_card) {
		try {
			String result = "";
			ObjectMapper mapper = new ObjectMapper();
			HashMap<String, List<Pilot>> map = new HashMap<String, List<Pilot>>();
			map.put("result",
					repository.getPilot(id_card));
			result = mapper.writeValueAsString(map);
			return result;
		} catch (Exception ex) {
			log.error(ex.getMessage());
			return "";
		}
	}

	@Override
	public String getPilotByName(String name) {
		try {
			String result = "";
			ObjectMapper mapper = new ObjectMapper();
			HashMap<String, List<Pilot>> map = new HashMap<String, List<Pilot>>();
			map.put("result",
					repository.getPilotByName(name));
			result = mapper.writeValueAsString(map);
			return result;
		} catch (Exception ex) {
			log.error(ex.getMessage());
			return "";
		}
	}
	
}
